#include "include.h"
#include "bsp_led.h"

#define MAX_GRB_LED 7
#define LED_ON 1
#define LED_OFF 0
#define BREATHE_ON 0
#define BREATHE_OFF 0x3000//d000

led_param_t led_info;
u8 rgb_led_buf[7];
u8 active_led_buf[7];
u32 delay_ticks;

u8 random_num;
//led_status_t grow_info;
typedef struct
{
	u8 tick_start;
	u8 tick_cnt;
	u8 fade_start;
	u16 fade_steps;	//渐变过程变量
	u16 color_switch_time;	//过多长时间切换颜色Calm,Aurora,Energy,pulse需要
	u16 fade_offset;
}disp_status_t;
disp_status_t grow_info;
u8 cur_duty_table[7];
u8 next_duty_table[7];
AT(.com_text.rgb.table)
const u8 grow_table_1[7]=
{
	LED_ON,LED_OFF,LED_ON,LED_OFF,LED_ON,LED_OFF,LED_ON
};
AT(.com_text.rgb.table)
const u8 grow_table_2[7]=
{
	LED_OFF,LED_ON,LED_OFF,LED_ON,LED_OFF,LED_ON,LED_OFF
};



AT(.com_text.rgb)
void com_memcpy(void *dst,const void *src,size_t length)
{
	while(length--)
	{
		*(char*)dst=*(char*)src;
		dst=(char*)dst+1;
		src=(char*)src+1;
	}
}
AT(.com_text.rgb)
void com_memset(void *s,int c,size_t n)
{
	const unsigned char uc = c;
	unsigned char *su;
	for(su = s;0 < n;++su,--n)
	*su = uc;
}

AT(.com_text.led_disp)
void rgb_led_set(void)
{
	u8 i;
	#if LED_PWM_MODE
	for(i=0;i<MAX_GRB_LED;i++)
	{
		LED_SET_ONOFF(i,rgb_led_buf[i]);
	}
	#else
	for(i=0;i<MAX_GRB_LED;i++)
	{
		(rgb_led_buf[i]==LED_ON)?LED_DISPLAY_ON(i):LED_DISPLAY_OFF(i);
	}
	#endif


}
AT(.com_text.led_disp)
void rgb_led_set_index(void)
{
	u8 i;
	#if LED_PWM_MODE
	for(i=0;i<MAX_GRB_LED;i++)
	{
		if(active_led_buf[i])
		{
			LED_SET_ONOFF(i,rgb_led_buf[i]);
		}
	}
	#else
	for(i=0;i<MAX_GRB_LED;i++)
	{
		if(active_led_buf[i])
		{
			(active_led_buf[i]==LED_ON)?LED_DISPLAY_ON(i):LED_DISPLAY_OFF(i);
		}
	}
	#endif

}

AT(.text.led_disp)
void bsp_led_Sequence_1_init(void)
{
	led_info.time_cnt=0;
	led_info.time_out=1;
	led_info.led_step=0;
	led_info.timer_start=1;
	com_memset(rgb_led_buf,LED_OFF,MAX_GRB_LED);
	rgb_led_set();
}
AT(.com_text.led_disp)
void bsp_led_Sequence_1(void)
{

	if(led_info.led_step>5)
	{
		led_info.led_step=4;
	}
	switch(led_info.led_step)
	{
		case 0:
		    rgb_led_buf[LED_1]=LED_ON;
			rgb_led_buf[LED_7]=LED_ON;
			break;
		case 1:
		    rgb_led_buf[LED_2]=LED_ON;
			rgb_led_buf[LED_6]=LED_ON;
			break;
		case 2:
		    rgb_led_buf[LED_3]=LED_ON;
			rgb_led_buf[LED_5]=LED_ON;
			break;
		case 3:
			rgb_led_buf[LED_4]=LED_ON;
			break;
		case 4:
			com_memset(rgb_led_buf,LED_OFF,MAX_GRB_LED);
			break;
		case 5:
			com_memset(rgb_led_buf,LED_ON,MAX_GRB_LED);
			break;
	}
	rgb_led_set();
	led_info.time_cnt=0;
	if(led_info.led_step<4)
	{
		led_info.time_out=3;
	}
	else
	{
		led_info.time_out=1;
	}
	led_info.led_step++;

}




AT(.com_text.led_disp)
void bsp_led_Sequence_2(void)
{
	//printf("led_step:%d\n",led_info.led_step);

	if(led_info.led_step>1)
	{
		led_info.led_step=0;
	}
	switch(led_info.led_step)
	{
		case 0:
			com_memcpy(cur_duty_table,grow_table_1,MAX_GRB_LED);
			com_memcpy(next_duty_table,grow_table_2,MAX_GRB_LED);
			break;
		case 1:
		    com_memcpy(cur_duty_table,grow_table_2,MAX_GRB_LED);
			com_memcpy(next_duty_table,grow_table_1,MAX_GRB_LED);
			break;
		default:
			break;
	}
	//printf("init duty:");
	//print_r(cur_duty_table,7);
	//print_r(next_duty_table,7);
	//printf("\n");
	grow_info.fade_steps=0;

	grow_info.fade_start=1;
	led_info.led_step++;

}
AT(.text.led_disp)
void bsp_led_Sequence_2_init(void)
{
	grow_info.fade_start=0;
	led_info.led_step=0;
	led_info.timer_start=0;
	grow_info.fade_steps=0;
	grow_info.color_switch_time=40;//500ms 周期，20 ms timer
	grow_info.fade_offset=BREATHE_OFF/grow_info.color_switch_time;
	com_memset(rgb_led_buf,LED_OFF,MAX_GRB_LED);
	rgb_led_set();
	//com_memset(rgb_led_buf,LED_OFF,MAX_GRB_LED);
	//memcpy(cur_duty_table,grow_table_1,MAX_GRB_LED);
	//memcpy(next_duty_table,grow_table_2,MAX_GRB_LED);
	bsp_led_Sequence_2();
	grow_info.fade_start=1;
}
AT(.com_text.led_disp)
u32 get_fade_diff(u8 cur_duty, u8 to_duty, u32 fade_counter, u32 fade_offset)
{
	u32 fade_diff;
	//current_color=(current_color*light_info.rgb_time)/255;
	//to_color=(to_color*light_info.rgb_time)/255;
	if(cur_duty > to_duty)
	{
		if(BREATHE_OFF>(fade_counter*fade_offset))
		{
			fade_diff=BREATHE_OFF-(fade_counter*fade_offset);
		}
		else
		{
			fade_diff=BREATHE_ON;
		}
	}
	else
	{
		if(BREATHE_OFF>(fade_counter*fade_offset))
		{
			fade_diff=fade_counter*fade_offset;
		}
		else
		{
			fade_diff=BREATHE_OFF;
		}

	}

	return fade_diff;
}
/* 颜色渐变模式 glow 模式 = (0~255) */
AT(.com_text.led_disp)
u8 display_glow_mode(disp_status_t* p_disp_status)
{
    u8 i;
	u16 set_duty_table;	/* fade 差值 */

	if(p_disp_status->fade_steps > p_disp_status->color_switch_time)
	{
		p_disp_status->fade_steps = 0;
		grow_info.fade_start=0;
		return 1;
	}
	//printf("set duty: ");
	for(i=0;i<MAX_GRB_LED;i++)
	{
		set_duty_table = get_fade_diff(
				cur_duty_table[i],
				next_duty_table[i],
				p_disp_status->fade_steps,
				p_disp_status->fade_offset);

		LED_SET_BREATHE(i, set_duty_table);
	}
	//printf(" 0x%x ",set_duty_table);
	//printf("\n");
	return 0;
}
AT(.com_text.led_disp)
void bsp_led_Sequence_2_timer(void)
{
	if(led_info.led_mode!=LED_SEQUENCE_2)
	{
		return;
	}
	if(tick_check_expire(delay_ticks,50))
	{
		delay_ticks = tick_get();
		grow_info.fade_steps++;
		if(display_glow_mode(&grow_info))
		{
			bsp_led_Sequence_2();
		}

	}
}




AT(.text.led_disp)
void bsp_led_Sequence_3_init(void)
{
	led_info.timer_start=0;
}
AT(.com_text.led_disp.table)
const u16 engegy_table[13] = {0x200,0x500,0x800,0x1000,0x1500,0x2000,0x3000,0x4000,0x6000,0x8000,0xB000,0xe000,0xffff};
u8 prev_level;
u8 group=0;
const u8 sequence_3_led_mode[3][7]=
{
	{1,0,1,0,1,0,1},
	{0,1,0,1,0,1,0},
};

AT(.com_text.led_disp)
void rgb_led_push_music(u8 onoff)
{
	u8 i;

#if LED_PWM_MODE
	if(sys_cb.mic_onoff)
	{
		for(i=0;i<MAX_GRB_LED;i++)
		{
			if(onoff)
			{
				LED_SET_ONOFF(i,LED_ON);
			}
			else
			{
				if(sequence_3_led_mode[1][i])
				{
					LED_SET_ONOFF(i,LED_OFF);
				}
			}
		}
		return;
	}
	for(i=0;i<MAX_GRB_LED;i++)
	{
		if(onoff)
		{
			LED_SET_ONOFF(i,sequence_3_led_mode[group][i]);
		}
		else
		{
			LED_SET_ONOFF(i,LED_OFF);
		}
	}
#else
	for(i=0;i<MAX_GRB_LED;i++)
	{
		if(onoff)
		{
			(sequence_3_led_mode[group][i])?LED_DISPLAY_ON(i):LED_DISPLAY_OFF(i);
		}
		else
		{
			LED_DISPLAY_OFF(i);
		}
	}
#endif
	if(!onoff)
	{
		group=!group;
	}
}

AT(.com_text.led_disp)
void bsp_led_Sequence_3(void)
{
	#if 1
	u32 energy;
	u8 i,cur_level=0;
	if(led_info.led_mode!=LED_SEQUENCE_3)
	{
		return;
	}
	if(tick_check_expire(delay_ticks,50))
	{
		delay_ticks = tick_get();
		#if 0
		cur_level=get_random(6);
		#else
		energy = dac_pcm_pow_calc();
		//printf("energy:0x%x\n",energy);
		for(i=0;i<13;i++)
		{
			if(energy<engegy_table[i])
			{
				cur_level=i;
				break;
			}
		}
		#endif
		if(cur_level>prev_level)
		{
			rgb_led_push_music(0);
			#if 0
			if((cur_level-prev_level)&&(cur_level>2))
			{
				rgb_led_push_music(0);
			}
			else
			{
				rgb_led_push_music(1);
			}
			#endif
		}
		else
		{
			rgb_led_push_music(1);
		}
		prev_level=cur_level;
	}
	#endif
}

AT(.text.led_disp)
void bsp_led_Sequence_4_init(void)
{
	led_info.time_cnt=0;
	led_info.time_out=1;
	led_info.led_step=0;
	led_info.timer_start=1;
	com_memset(rgb_led_buf,LED_OFF,MAX_GRB_LED);
}
AT(.com_text.led_disp)
void bsp_led_Sequence_4(void)
{

	if(led_info.led_step>12)
	{
		led_info.led_step=1;
	}
	switch(led_info.led_step)
	{
		case 0:
		    rgb_led_buf[LED_1]=LED_ON;
			break;
		case 1:
			rgb_led_buf[LED_1]=LED_OFF;
		    rgb_led_buf[LED_2]=LED_ON;
			break;
		case 2:
			rgb_led_buf[LED_2]=LED_OFF;
		    rgb_led_buf[LED_3]=LED_ON;
			break;
		case 3:
			rgb_led_buf[LED_3]=LED_OFF;
			rgb_led_buf[LED_4]=LED_ON;
			break;
		case 4:
			rgb_led_buf[LED_4]=LED_OFF;
			rgb_led_buf[LED_5]=LED_ON;
			break;
		case 5:
			rgb_led_buf[LED_5]=LED_OFF;
			rgb_led_buf[LED_6]=LED_ON;
			break;
		case 6:
			rgb_led_buf[LED_6]=LED_OFF;
			rgb_led_buf[LED_7]=LED_ON;
			break;
		case 7:
			rgb_led_buf[LED_7]=LED_OFF;
		    rgb_led_buf[LED_6]=LED_ON;
			break;
		case 8:
			rgb_led_buf[LED_6]=LED_OFF;
		    rgb_led_buf[LED_5]=LED_ON;
			break;
		case 9:
			rgb_led_buf[LED_5]=LED_OFF;
			rgb_led_buf[LED_4]=LED_ON;
			break;
		case 10:
			rgb_led_buf[LED_4]=LED_OFF;
			rgb_led_buf[LED_3]=LED_ON;
			break;
		case 11:
			rgb_led_buf[LED_3]=LED_OFF;
			rgb_led_buf[LED_2]=LED_ON;
			break;
		case 12:
			rgb_led_buf[LED_2]=LED_OFF;
			rgb_led_buf[LED_1]=LED_ON;
			break;
	}
	rgb_led_set();
	led_info.time_cnt=0;
	led_info.time_out=1;
	led_info.led_step++;
}


AT(.com_text.led_disp)
void bsp_get_random_led(void)
{
	u8 led_random_num;
	u8 num_cnt=0,tmp_data;
	while(1)
	{
		led_random_num=get_random(7);
		if(led_random_num>=3&&led_random_num<=5)
		{
			break;
		}
	}
	random_num=0;
	while(1)
	{
		tmp_data=get_random(7);
		if((random_num&(0x01<<tmp_data))==0)
		{
			num_cnt++;
			random_num|=0x01<<tmp_data;
		}
		if(num_cnt>=led_random_num)
		{
			break;
		}
	}
}

AT(.text.led_disp)
void bsp_led_Sequence_5_init(void)
{
	led_info.time_cnt=0;
	led_info.time_out=1;
	led_info.led_step=0;
	led_info.timer_start=0;
	//bsp_get_random_led();
}

AT(.com_text.led_disp)
void bsp_led_Sequence_5(void)
{
	u8 i;
	com_memset(rgb_led_buf,LED_OFF,MAX_GRB_LED);
	//printf("random_num:0x%x\n",random_num);
	for(i=0;i<MAX_GRB_LED;i++)
	{
		if(random_num&(0x01<<i))
		{
			rgb_led_buf[i]=LED_ON;
		}
	}
	rgb_led_set();
	//led_info.time_cnt=0;
	//led_info.time_out=5;
}
AT(.com_text.led_disp)
void bsp_led_Sequence_5_random_led_timer(void)
{

	if(led_info.led_mode!=LED_SEQUENCE_5)
	{
		return;
	}
	if(tick_check_expire(delay_ticks,200))
	{
		delay_ticks = tick_get();
		bsp_get_random_led();
		bsp_led_Sequence_5();
	}
}

AT(.text.led_disp)
void bsp_led_Sequence_6_init(void)
{
	led_info.timer_start=0;
	com_memset(rgb_led_buf,LED_ON,MAX_GRB_LED);
	rgb_led_set();
}


AT(.text.led_disp)
void bsp_led_Sequence_7_init(void)
{
	led_info.time_cnt=0;
	led_info.time_out=2;
	led_info.led_step=0;
	led_info.timer_start=1;
	com_memset(rgb_led_buf,LED_OFF,MAX_GRB_LED);
	rgb_led_set();
}
AT(.com_text.led_disp)
void bsp_led_Sequence_7(void)
{

	if(led_info.led_step>3)
	{
		led_info.led_step=0;
		led_info.timer_start=0;
	}
	switch(led_info.led_step)
	{
		case 0:
			rgb_led_buf[LED_1]=LED_ON;
			rgb_led_buf[LED_7]=LED_ON;
			break;
		case 1:
			rgb_led_buf[LED_2]=LED_ON;
			rgb_led_buf[LED_6]=LED_ON;
			break;
		case 2:
			rgb_led_buf[LED_3]=LED_ON;
			rgb_led_buf[LED_5]=LED_ON;
			break;
		case 3:
			rgb_led_buf[LED_4]=LED_ON;
			break;
		default:
			break;
	}
	rgb_led_set();
	led_info.time_cnt=0;
	led_info.time_out=1;
	led_info.led_step++;
	if(led_info.led_step>3)
	{
		led_info.timer_start=0;
	}
}

AT(.text.led_disp)
void bsp_led_Sequence_8_init(void)
{
	led_info.time_cnt=0;
	led_info.time_out=2;
	led_info.led_step=0;
	led_info.timer_start=1;
	com_memset(rgb_led_buf,LED_ON,MAX_GRB_LED);
	rgb_led_set();
}

AT(.com_text.led_disp)
void bsp_led_Sequence_8(void)
{

	
	switch(led_info.led_step)
	{
		case 0:
			rgb_led_buf[LED_4]=LED_OFF;
			break;
		case 1:
			rgb_led_buf[LED_3]=LED_OFF;
			rgb_led_buf[LED_5]=LED_OFF;
			break;
		case 2:
			rgb_led_buf[LED_2]=LED_OFF;
			rgb_led_buf[LED_6]=LED_OFF;
			break;
		case 3:
			rgb_led_buf[LED_1]=LED_OFF;
			rgb_led_buf[LED_7]=LED_OFF;
			break;
		default:
			break;
	}
	rgb_led_set();
	led_info.time_cnt=0;
	led_info.time_out=1;
	led_info.led_step++;
	if(led_info.led_step>3)
	{
		led_info.led_step=0;
		led_info.timer_start=0;
	}
}
AT(.text.led_disp)
void bsp_led_Sequence_9_init(void)
{
	led_info.time_cnt=0;
	led_info.time_out=1;
	led_info.led_step=0;
	led_info.timer_start=0;
	com_memset(rgb_led_buf,LED_ON,MAX_GRB_LED);
	rgb_led_set();
}


AT(.com_text.led_disp)
void bsp_led_Sequence_9(void)
{
	#if 0
	if(led_info.led_step>12)
	{
		led_info.led_step=1;
	}
	switch(led_info.led_step)
	{
		case 0:
		    rgb_led_buf[LED_1]=LED_ON;
			break;
		case 1:
			rgb_led_buf[LED_1]=LED_OFF;
		    rgb_led_buf[LED_2]=LED_ON;
			break;
		case 2:
			rgb_led_buf[LED_2]=LED_OFF;
		    rgb_led_buf[LED_3]=LED_ON;
			break;
		case 3:
			rgb_led_buf[LED_3]=LED_OFF;
			rgb_led_buf[LED_4]=LED_ON;
			break;
		case 4:
			rgb_led_buf[LED_4]=LED_OFF;
			rgb_led_buf[LED_5]=LED_ON;
			break;
		case 5:
			rgb_led_buf[LED_5]=LED_OFF;
			rgb_led_buf[LED_6]=LED_ON;
			break;
		case 6:
			rgb_led_buf[LED_6]=LED_OFF;
			rgb_led_buf[LED_7]=LED_ON;
			break;
		case 7:
			rgb_led_buf[LED_7]=LED_OFF;
		    rgb_led_buf[LED_6]=LED_ON;
			break;
		case 8:
			rgb_led_buf[LED_6]=LED_OFF;
		    rgb_led_buf[LED_5]=LED_ON;
			break;
		case 9:
			rgb_led_buf[LED_5]=LED_OFF;
			rgb_led_buf[LED_4]=LED_ON;
			break;
		case 10:
			rgb_led_buf[LED_4]=LED_OFF;
			rgb_led_buf[LED_3]=LED_ON;
			break;
		case 11:
			rgb_led_buf[LED_3]=LED_OFF;
			rgb_led_buf[LED_2]=LED_ON;
			break;
		case 12:
			rgb_led_buf[LED_2]=LED_OFF;
			rgb_led_buf[LED_1]=LED_ON;
			break;
	}
	rgb_led_set();
	led_info.time_cnt=0;
	led_info.time_out=1;
	led_info.led_step++;
	#endif
}
AT(.text.led_disp)
void bsp_led_Sequence_9a_init(void)
{
	led_info.time_cnt=0;
	led_info.time_out=2;
	led_info.led_step=0;
	led_info.timer_start=1;
	com_memset(rgb_led_buf,LED_ON,MAX_GRB_LED);
	rgb_led_set();
}
AT(.com_text.led_disp)
void bsp_led_Sequence_9a(void)
{
	if(led_info.led_step==0)
	{
		led_info.led_step=1;
		com_memset(rgb_led_buf,LED_OFF,MAX_GRB_LED);
	}
	else
	{
		led_info.led_step=0;
		com_memset(rgb_led_buf,LED_ON,MAX_GRB_LED);
	}
	rgb_led_set();
	led_info.time_out=2;
	led_info.time_cnt=0;
}

AT(.text.led_disp)
void bsp_led_Sequence_10a_init(void)
{
	led_info.time_cnt=0;
	led_info.time_out=1;
	led_info.led_step=0;
	led_info.timer_start=1;
	com_memset(rgb_led_buf,LED_OFF,MAX_GRB_LED);
	rgb_led_set();
}
AT(.com_text.led_disp)
void bsp_led_Sequence_10a(void)
{
	led_info.led_step++;
	if(led_info.led_step>1)
	{
		led_info.led_step=0;
	}
	switch(led_info.led_step)
	{
		case 0:
			com_memset(rgb_led_buf,LED_ON,MAX_GRB_LED);
			break;
		case 1:
			com_memset(rgb_led_buf,LED_OFF,MAX_GRB_LED);
			break;
		default:
			break;
	}
	rgb_led_set();
	led_info.time_cnt=0;
	led_info.time_out=3;

}
AT(.text.led_disp)
void bsp_led_Sequence_10a_1_init(void)
{
	led_info.time_cnt=0;
	led_info.time_out=20;
	led_info.led_step=0;
	led_info.timer_start=1;
	com_memset(rgb_led_buf,LED_ON,MAX_GRB_LED);
	rgb_led_set();
}

AT(.com_text.led_disp)
void bsp_led_Sequence_10a_1(void)
{
	led_info.timer_start=0;
	bsp_set_led_mode(LED_SEQUENCE_2);
}
AT(.text.led_disp)
void bsp_led_Sequence_10b_init(void)
{
	led_info.time_cnt=0;
	led_info.time_out=20;
	led_info.led_step=0;
	led_info.timer_start=1;
	com_memset(rgb_led_buf,LED_OFF,MAX_GRB_LED);
	rgb_led_buf[LED_1]=LED_ON;
	com_memset(active_led_buf,0x0,MAX_GRB_LED);
	rgb_led_set();
	//active_led_buf[LED_1]=1;
	//rgb_led_set_index();
}
AT(.com_text.led_disp)
void bsp_led_Sequence_10b(void)
{
	led_info.timer_start=0;
	bsp_set_led_mode(LED_SEQUENCE_2);
}

AT(.com_text.led_disp)
void bsp_led_Sequence_11_init(void)
{
	led_info.timer_start=0;
	com_memset(rgb_led_buf,LED_OFF,MAX_GRB_LED);
	rgb_led_set();
}

AT(.text.led_disp)
void bsp_led_up_and_down_init(void)
{
	led_info.time_cnt=0;
	led_info.time_out=1;
	led_info.led_step=0;
	led_info.timer_start=2;
	com_memset(rgb_led_buf,LED_ON,MAX_GRB_LED);
	rgb_led_set();
}

AT(.text.led_disp)
void bsp_led_up_and_down(void)
{
	switch(led_info.led_step)
	{
		case 0:
		    rgb_led_buf[LED_4]=LED_OFF;
			break;
		case 1:
		    rgb_led_buf[LED_3]=LED_OFF;
			rgb_led_buf[LED_5]=LED_OFF;
			break;
		case 2:
		    rgb_led_buf[LED_2]=LED_OFF;
			rgb_led_buf[LED_6]=LED_OFF;
			break;
		case 3:
			rgb_led_buf[LED_1]=LED_OFF;
			rgb_led_buf[LED_7]=LED_OFF;
			break;
		case 4:
			rgb_led_buf[LED_1]=LED_ON;
			rgb_led_buf[LED_7]=LED_ON;
			break;
		case 5:
		    rgb_led_buf[LED_2]=LED_ON;
			rgb_led_buf[LED_6]=LED_ON;
			break;
		case 6:
		    rgb_led_buf[LED_3]=LED_ON;
			rgb_led_buf[LED_5]=LED_ON;
			break;
		case 7:
			rgb_led_buf[LED_4]=LED_ON;
			break;
	}
	rgb_led_set();
	led_info.time_cnt=0;
	led_info.time_out=2;
	led_info.led_step++;
	if(led_info.led_step>7)
	{
		led_info.timer_start=0;
		led_info.led_step=0;
	}
}
AT(.text.led_disp)
void bsp_led_back_and_forth_init(void)
{
	led_info.time_cnt=0;
	led_info.time_out=1;
	led_info.led_step=0;
	led_info.timer_start=1;
	com_memset(rgb_led_buf,LED_OFF,MAX_GRB_LED);
	rgb_led_set();
}

AT(.text.led_disp)
void bsp_led_back_and_forth(void)
{
	if(led_info.led_step>12)
	{
		led_info.led_step=1;
	}
	switch(led_info.led_step)
	{
		case 0:
		    rgb_led_buf[LED_1]=LED_ON;
			break;
		case 1:
			rgb_led_buf[LED_1]=LED_OFF;
		    rgb_led_buf[LED_2]=LED_ON;
			break;
		case 2:
			rgb_led_buf[LED_2]=LED_OFF;
		    rgb_led_buf[LED_3]=LED_ON;
			break;
		case 3:
			rgb_led_buf[LED_3]=LED_OFF;
			rgb_led_buf[LED_4]=LED_ON;
			break;
		case 4:
			rgb_led_buf[LED_4]=LED_OFF;
			rgb_led_buf[LED_5]=LED_ON;
			break;
		case 5:
			rgb_led_buf[LED_5]=LED_OFF;
			rgb_led_buf[LED_6]=LED_ON;
			break;
		case 6:
			rgb_led_buf[LED_6]=LED_OFF;
			rgb_led_buf[LED_7]=LED_ON;
			break;
		case 7:
			rgb_led_buf[LED_7]=LED_OFF;
		    rgb_led_buf[LED_6]=LED_ON;
			break;
		case 8:
			rgb_led_buf[LED_6]=LED_OFF;
		    rgb_led_buf[LED_5]=LED_ON;
			break;
		case 9:
			rgb_led_buf[LED_5]=LED_OFF;
			rgb_led_buf[LED_4]=LED_ON;
			break;
		case 10:
			rgb_led_buf[LED_4]=LED_OFF;
			rgb_led_buf[LED_3]=LED_ON;
			break;
		case 11:
			rgb_led_buf[LED_3]=LED_OFF;
			rgb_led_buf[LED_2]=LED_ON;
			break;
		case 12:
			rgb_led_buf[LED_2]=LED_OFF;
			rgb_led_buf[LED_1]=LED_ON;
			break;
	}
	rgb_led_set();
	led_info.time_cnt=0;
	led_info.time_out=1;
	led_info.led_step++;
}

AT(.text.led_disp)
void bsp_led_on_and_downward_init(void)
{
	led_info.time_cnt=0;
	led_info.time_out=0;
	led_info.led_step=0;
	led_info.timer_start=1;
	com_memset(rgb_led_buf,LED_ON,MAX_GRB_LED);
	rgb_led_buf[LED_4]=LED_OFF;
	rgb_led_set();
}
AT(.text.led_disp)
void bsp_led_on_and_downward(void)
{
	switch(led_info.led_step)
	{
		case 0:
			rgb_led_buf[LED_3]=LED_OFF;
			rgb_led_buf[LED_5]=LED_OFF;
			break;
		case 1:
		    rgb_led_buf[LED_2]=LED_OFF;
			rgb_led_buf[LED_6]=LED_OFF;
			break;
		case 2:
		    rgb_led_buf[LED_1]=LED_OFF;
			rgb_led_buf[LED_7]=LED_OFF;
			break;
	}
	rgb_led_set();
	led_info.time_cnt=0;
	led_info.time_out=1;
	led_info.led_step++;
	if(led_info.led_step>2)
	{
		led_info.led_step=0;
		led_info.timer_start=0;
	}
}

AT(.text.led_disp)
void bsp_led_upward_and_flash_init(void)
{
	led_info.time_cnt=0;
	led_info.time_out=1;
	led_info.led_step=0;
	led_info.timer_start=1;
	com_memset(rgb_led_buf,LED_OFF,MAX_GRB_LED);
	rgb_led_set();
}
AT(.text.led_disp)
void bsp_led_upward_and_flash(void)
{
	if(led_info.led_step>5)
	{
		led_info.led_step=4;
	}
	switch(led_info.led_step)
	{
		case 0:
			rgb_led_buf[LED_1]=LED_ON;
			rgb_led_buf[LED_7]=LED_ON;
			break;
		case 1:
		    rgb_led_buf[LED_2]=LED_ON;
			rgb_led_buf[LED_6]=LED_ON;
			break;
		case 2:
		    rgb_led_buf[LED_3]=LED_ON;
			rgb_led_buf[LED_5]=LED_ON;
			break;
		case 3:
			rgb_led_buf[LED_4]=LED_ON;
			break;
		case 4:
			com_memset(rgb_led_buf,LED_OFF,MAX_GRB_LED);
			break;
		case 5:
			com_memset(rgb_led_buf,LED_ON,MAX_GRB_LED);
			break;
	}
	rgb_led_set();
	led_info.time_cnt=0;
	led_info.time_out=1;
	led_info.led_step++;
}

AT(.text.led_disp)
void bsp_led_alternate_flash_init(void)
{
	led_info.time_cnt=0;
	led_info.time_out=1;
	led_info.led_step=1;
	led_info.timer_start=1;
	rgb_led_buf[LED_1]=LED_ON;
	rgb_led_buf[LED_7]=LED_ON;
	rgb_led_set();
}
AT(.text.led_disp)
void bsp_led_alternate_flash(void)
{
	if(led_info.led_step>5)
	{
		led_info.led_step=4;
	}
	switch(led_info.led_step)
	{
		case 0:
			break;
		case 1:
		    rgb_led_buf[LED_2]=LED_ON;
			rgb_led_buf[LED_6]=LED_ON;
			break;
		case 2:
		    rgb_led_buf[LED_3]=LED_ON;
			rgb_led_buf[LED_5]=LED_ON;
			break;
		case 3:
			rgb_led_buf[LED_4]=LED_ON;
			break;
		case 4:
			rgb_led_buf[LED_1]=LED_ON;
			rgb_led_buf[LED_3]=LED_ON;
			rgb_led_buf[LED_5]=LED_ON;
			rgb_led_buf[LED_7]=LED_ON;
			rgb_led_buf[LED_2]=LED_OFF;
			rgb_led_buf[LED_6]=LED_OFF;
			rgb_led_buf[LED_4]=LED_OFF;
			break;
		case 5:
			rgb_led_buf[LED_1]=LED_OFF;
			rgb_led_buf[LED_3]=LED_OFF;
			rgb_led_buf[LED_5]=LED_OFF;
			rgb_led_buf[LED_7]=LED_OFF;
			rgb_led_buf[LED_2]=LED_ON;
			rgb_led_buf[LED_6]=LED_ON;
			rgb_led_buf[LED_4]=LED_ON;
			break;
	}
	rgb_led_set();
	led_info.time_cnt=0;
	led_info.time_out=2;
	led_info.led_step++;
}

AT(.text.led_disp)
void bsp_led_flash_init(void)
{
	led_info.time_cnt=0;
	led_info.time_out=1;
	led_info.led_step=0;
	led_info.timer_start=1;
	com_memset(rgb_led_buf,LED_OFF,MAX_GRB_LED);
	rgb_led_set();
}
AT(.text.led_disp)
void bsp_led_flash(void)
{
	if(led_info.led_step==0)
	{
		com_memset(rgb_led_buf,LED_ON,MAX_GRB_LED);
		led_info.led_step=1;
	}
	else
	{
		com_memset(rgb_led_buf,LED_OFF,MAX_GRB_LED);
		led_info.led_step=0;
	}
	rgb_led_set();
	led_info.time_cnt=0;
	led_info.time_out=1;
}
AT(.text.led_disp)
void bsp_led_all_on_init(void)
{
	led_info.time_cnt=0;
	led_info.time_out=0;
	led_info.led_step=0;
	led_info.timer_start=0;
	com_memset(rgb_led_buf,LED_ON,MAX_GRB_LED);
	rgb_led_set();
}

AT(.text.led_disp)
void bsp_led_downward_off_init(void)
{
	led_info.time_cnt=0;
	led_info.time_out=3;
	led_info.led_step=0;
	led_info.timer_start=1;
	com_memset(rgb_led_buf,LED_ON,MAX_GRB_LED);
	rgb_led_set();
}

AT(.com_text.led_disp)
void bsp_led_downward_off(void)
{

	switch(led_info.led_step)
	{
		case 0:
			rgb_led_buf[LED_4]=LED_OFF;
			break;
		case 1:
			rgb_led_buf[LED_3]=LED_OFF;
			rgb_led_buf[LED_5]=LED_OFF;
			break;
		case 2:
			rgb_led_buf[LED_2]=LED_OFF;
			rgb_led_buf[LED_6]=LED_OFF;
			break;
		case 3:
			rgb_led_buf[LED_1]=LED_OFF;
			rgb_led_buf[LED_7]=LED_OFF;
			break;
		default:
			break;
	}
	rgb_led_set();
	led_info.time_cnt=0;
	led_info.time_out=3;
	led_info.led_step++;
	if(led_info.led_step>3)
	{
		led_info.led_step=0;
		led_info.timer_start=0;
	}
}


AT(.com_text.led_disp)
void bsp_sequence_display_timer(void)
{
	bsp_led_Sequence_2_timer();
	bsp_led_Sequence_5_random_led_timer();
	bsp_led_Sequence_3();
}

AT(.com_text.led_disp)
void bsp_led_Sequence_display(void)
{
	if(!led_info.timer_start)
	{
		return;
	}
	led_info.time_cnt++;
	if(led_info.time_cnt<led_info.time_out)
	{
		return;
	}
	switch(led_info.led_mode)
	{
		case LED_SEQUENCE_1:
			bsp_led_Sequence_1();
			break;
		case LED_SEQUENCE_2:
			//bsp_led_Sequence_2();
			break;
		case LED_SEQUENCE_3:
			bsp_led_Sequence_3();
			break;
		case LED_SEQUENCE_4:
			bsp_led_Sequence_4();
			break;
		case LED_SEQUENCE_5:
			//bsp_led_Sequence_5();
			break;
		case LED_SEQUENCE_7:
			bsp_led_Sequence_7();
			break;
		case LED_SEQUENCE_8:
			bsp_led_Sequence_8();
			break;
		case LED_SEQUENCE_9:
			bsp_led_Sequence_9();
			break;
		case LED_SEQUENCE_9A:
			bsp_led_Sequence_9a();
			break;
		case LED_SEQUENCE_10A:
			bsp_led_Sequence_10a();
			break;
		case LED_SEQUENCE_10A_1:
			bsp_led_Sequence_10a_1();
			break;
		case LED_SEQUENCE_10B:
			bsp_led_Sequence_10b();
			break;

		case LED_DOWNWARD_UPWARD:
			bsp_led_up_and_down();
			break;
    	case LED_BACK_AND_FORTH:
			bsp_led_back_and_forth();
			break;
		case LED_ON_AND_DOWNWARD:
			bsp_led_on_and_downward();
			break;
    	case LED_UPWARD_AND_FLASH:
			bsp_led_upward_and_flash();
			break;
    	case LED_ALL_FLASH:
			bsp_led_flash();
			break;
    	case LED_ALTERNATE_FLASH:
			bsp_led_alternate_flash();
			break;
    	case LED_DOWNWARD_OFF:
			bsp_led_downward_off();
			break;
		default:
			break;
	}
}
AT(.com_text.led_disp)
void bsp_led_timer(void)
{
	if(led_info.led_mode!=0)
	{
		bsp_led_Sequence_display();
	}
}

void bsp_led_mode_init(void)
{
	printf("light mode:%d\n",led_info.led_mode);
	switch(led_info.led_mode)
	{
		case LED_SEQUENCE_1:
			bsp_led_Sequence_1_init();
			break;
		case LED_SEQUENCE_2:
			bsp_led_Sequence_2_init();
			break;
		case LED_SEQUENCE_3:
			bsp_led_Sequence_3_init();
			break;
		case LED_SEQUENCE_4:
			bsp_led_Sequence_4_init();
			break;
		case LED_SEQUENCE_5:
			bsp_led_Sequence_5_init();
			break;
		case LED_SEQUENCE_6:
			bsp_led_Sequence_6_init();
			break;
		case LED_SEQUENCE_7:
			bsp_led_Sequence_7_init();
			break;
		case LED_SEQUENCE_8:
			bsp_led_Sequence_8_init();
			break;
		case LED_SEQUENCE_9:
			bsp_led_Sequence_9_init();
			break;
		case LED_SEQUENCE_9A:
			bsp_led_Sequence_9a_init();
			break;
		case LED_SEQUENCE_10A:
			bsp_led_Sequence_10a_init();
			break;
		case LED_SEQUENCE_10A_1:
			bsp_led_Sequence_10a_1_init();
			break;
		case LED_SEQUENCE_10B:
			bsp_led_Sequence_10b_init();
			break;
		case LED_SEQUENCE_11:
			bsp_led_Sequence_11_init();
			break;
		case LED_DOWNWARD_UPWARD:
			bsp_led_up_and_down_init();
			break;
    	case LED_BACK_AND_FORTH:
			bsp_led_back_and_forth_init();
			break;
   		case LED_ON_AND_DOWNWARD:
			bsp_led_on_and_downward_init();
			break;
    	case LED_UPWARD_AND_FLASH:
			bsp_led_upward_and_flash_init();
			break;
		case LED_ALL_ON:
			bsp_led_all_on_init();
			break;
    	case LED_ALL_FLASH:
			bsp_led_flash_init();
			break;
    	case LED_ALTERNATE_FLASH:
			bsp_led_alternate_flash_init();
			break;
    	case LED_DOWNWARD_OFF:
			bsp_led_downward_off_init();
			break;

		default:
		break;
	}
}
#if 0

u8 test_mode_index=0;

void test_color(void)
{
	printf("test_mode_index:%d\n",test_mode_index);
	//memset(rgb_led_buf,LED_OFF,MAX_GRB_LED);
	//rgb_led_buf[test_mode_index]=LED_ON;
	//LED_SET_ONOFF(test_mode_index,LED_ON);
	#if 0
	com_memset(rgb_led_buf,LED_OFF,MAX_GRB_LED);
	if(test_mode_index==7)
	{

	}
	else
	{
		rgb_led_buf[test_mode_index]=LED_ON;
	}
	rgb_led_set();
	test_mode_index++;
	if(test_mode_index>7)
	{
		test_mode_index=0;
	}
	#else
	if(test_mode_index>=LED_SEQUENCE_11)
	{
		test_mode_index=LED_SEQUENCE_1;
	}
	led_info.led_mode=test_mode_index;
	bsp_led_mode_init();
	test_mode_index++;
	#endif
	//rgb_led_set();
}
#endif
void bsp_set_led_mode(u8 led_mode)
{
	led_info.led_mode=led_mode;
	bsp_led_mode_init();
}

